<? /* 	
	GIOV Solution - Keep IT Simple
*/

class M_master_lesson_plan extends Model{
		
		//constructor
		function M_master_lesson_plan() {
			parent::Model();
		}
		
		//function for detail
		//get record list
		function detail_lesson_plan_list($master_id,$query,$start,$end) {
			$query = "SELECT * FROM detail_lesson_plan where dplan_master='".$master_id."'";
			$result = $this->db->query($query);
			$nbrows = $result->num_rows();
			$limit = $query." LIMIT ".$start.",".$end;			
			$result = $this->db->query($limit);  
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}
		//end of function
			
		//get master id, note : not done yet
		function get_master_id() {
			$query = "SELECT max(lesplan_id) as master_id from master_lesson_plan";
			$result = $this->db->query($query);
			if($result->num_rows()){
				$data=$result->row();
				$master_id=$data->master_id;
				return $master_id;
			}
			else{
				return '0';
				}
		}
		//eof


		function get_petugas($filter,$start,$end){
			
			$query = "SELECT karyawan_id,karyawan_nama,jabatan_nama FROM karyawan,jabatan 
						WHERE karyawan_jabatan=jabatan_id AND 
						(jabatan_nama='Dokter' OR jabatan_nama='Suster' OR jabatan_nama='Therapist') ";
			
			if ($filter<>""){
				$query .=eregi("WHERE",$query)? " AND ":" WHERE ";
				$query .= " (karyawan_nama LIKE '%".addslashes($filter)."%' OR 
							 jabatan_nama LIKE '%".addslashes($filter)."%')";
			}
			
			$result = $this->db->query($query);
			$nbrows = $result->num_rows();
			$limit = $query." LIMIT ".$start.",".$end;			
			$result = $this->db->query($limit);  
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
			
		}
		
	function get_class_list($query="",$start=0,$end=10){
		$sql="select * from class WHERE class_stat = 'Aktif'";
		if($query!=="")
			$sql.=" and (class_id like '%".$query."%' or class_name like '%".$query."%' or class_notes like '%".$query."%')";
	
		$result = $this->db->query($sql);
		$nbrows = $result->num_rows();
		$limit = $sql." LIMIT ".$start.",".$end;			
		$result = $this->db->query($limit); 
		if($nbrows>0){
			foreach($result->result() as $row){
				$arr[] = $row;
			}
			$jsonresult = json_encode($arr);
			return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
		} else {
			return '({"total":"0", "results":""})';
		}
	}

				
		//insert detail record
		function detail_anamnesa_problem_insert($panam_id ,$panam_master ,$panam_problem ,$panam_lamaproblem ,$panam_aksiproblem ,$panam_aksiket ){
				
			$query="";
		   	for($i = 0; $i < sizeof($panam_id); $i++){

				$data = array(
					"panam_master"=>$panam_master, 
					"panam_problem"=>$panam_problem[$i], 
					"panam_lamaproblem"=>$panam_lamaproblem[$i], 
					"panam_aksiproblem"=>$panam_aksiproblem[$i], 
					"panam_aksiket"=>$panam_aksiket[$i]
				);

				if($panam_id[$i]==0){
					$this->db->insert('anamnesa_problem', $data); 
					
					$query = $query.$this->db->insert_id();
					if($i<sizeof($panam_id)-1){
						$query = $query . ",";
					} 
					
				}else{
					$query = $query.$panam_id[$i];
					if($i<sizeof($panam_id)-1){
						$query = $query . ",";
					} 
					$this->db->where('panam_id', $panam_id[$i]);
					$this->db->update('anamnesa_problem', $data);
				}
			}
			
			if($query<>""){
				$sql="DELETE FROM anamnesa_problem WHERE  panam_master='".$panam_master."' AND
						panam_id NOT IN (".$query.")";
				$this->db->query($sql);
			}
			
			return '1';

		}
		//end of function

		// Function untuk insert Detail Lesson Plan
		function detail_lesson_plan_insert($temp_lesplan_id, $array_dplan_id, $array_dplan_time_start, $array_dplan_time_end, $array_dplan_daily_schedule, 
			 $array_dplan_week1_1, $array_dplan_week1_2, $array_dplan_week2_1, $array_dplan_week2_2, $array_dplan_week3_1, $array_dplan_week3_2, $array_dplan_week4_1, $array_dplan_week4_2 ){
	
		$datetime_now = date('Y-m-d H:i:s');

		// if($dfcl_master=="" || $dfcl_master==NULL || $dfcl_master==0){
		// 		$dfcl_master=$this->get_master_id();
		// }
		
		$size_array = sizeof($array_dplan_daily_schedule) - 1;
			for($i = 0; $i < sizeof($array_dplan_daily_schedule); $i++){
				$dplan_id = $array_dplan_id[$i];
				$dplan_master = $temp_lesplan_id;
				$dplan_time_start = $array_dplan_time_start[$i];
				$dplan_time_end = $array_dplan_time_end[$i];
				$dplan_daily_schedule = $array_dplan_daily_schedule[$i];
				$dplan_week1_1 = $array_dplan_week1_1[$i];
				$dplan_week1_2 = $array_dplan_week1_2[$i];
				$dplan_week2_1 = $array_dplan_week2_1[$i];
				$dplan_week2_2 = $array_dplan_week2_2[$i];
				$dplan_week3_1 = $array_dplan_week3_1[$i];
				$dplan_week3_2 = $array_dplan_week3_2[$i];
				$dplan_week4_1 = $array_dplan_week4_1[$i];
				$dplan_week4_2 = $array_dplan_week4_2[$i];

	
				$sql = "SELECT dplan_id
					FROM detail_lesson_plan
					WHERE dplan_id='".$dplan_id."'";
				$rs = $this->db->query($sql);
				
				if($rs->num_rows()){
				// jika datanya sudah ada maka update saja
					$dtu_detail_lesson_plan = array(
						"dplan_master"=>$dplan_master,
						"dplan_time_start"=>$dplan_time_start,
						"dplan_time_end"=>$dplan_time_end,
						"dplan_daily_schedule"=>$dplan_daily_schedule,
						"dplan_week1_1"=>$dplan_week1_1,
						"dplan_week1_2"=>$dplan_week1_2,
						"dplan_week2_1"=>$dplan_week2_1,
						"dplan_week2_2"=>$dplan_week2_2,
						"dplan_week3_1"=>$dplan_week3_1,
						"dplan_week3_2"=>$dplan_week3_2,
						"dplan_week4_1"=>$dplan_week4_1,
						"dplan_week4_2"=>$dplan_week4_2,
						"dplan_date_update"=>$datetime_now
					);
					$this->db->where('dplan_id', $temp_lesplan_id);
					$this->db->update('detail_lesson_plan', $dtu_detail_lesson_plan); 
				}else {
					$data = array(
						"dplan_master"=>$dplan_master,
						"dplan_time_start"=>$dplan_time_start,
						"dplan_time_end"=>$dplan_time_end,
						"dplan_daily_schedule"=>$dplan_daily_schedule,
						"dplan_week1_1"=>$dplan_week1_1,
						"dplan_week1_2"=>$dplan_week1_2,
						"dplan_week2_1"=>$dplan_week2_1,
						"dplan_week2_2"=>$dplan_week2_2,
						"dplan_week3_1"=>$dplan_week3_1,
						"dplan_week3_2"=>$dplan_week3_2,
						"dplan_week4_1"=>$dplan_week4_1,
						"dplan_week4_2"=>$dplan_week4_2,
						"dplan_date_create"=>$datetime_now
					);
					$this->db->insert('detail_lesson_plan', $data); 	
				}	
		}

		return '1';
	}


		
		//function for get list record
		function master_lesson_plan_list($filter,$start,$end){
			$query = "SELECT master_lesson_plan.* ,
						karyawan.karyawan_nama, karyawan.karyawan_id, karyawan.karyawan_no , karyawan.karyawan_kelamin,
						class.class_name , class.class_id, class.class_capacity, class.class_notes
						FROM master_lesson_plan
						LEFT JOIN karyawan on (karyawan.karyawan_id = master_lesson_plan.lesplan_teacher)
						LEFT JOIN class on (class.class_id = master_lesson_plan.lesplan_class)

						";
			
			// For simple search
			if ($filter<>""){
				$query .=eregi("WHERE",$query)? " AND ":" WHERE ";
				$query .= " (lesplan_code LIKE '%".addslashes($filter)."%' OR 
							 lesplan_theme LIKE '%".addslashes($filter)."%'
							 OR 
							 lesplan_subtheme LIKE '%".addslashes($filter)."%'
							 OR 
							 lesplan_note LIKE '%".addslashes($filter)."%'
							 )";
			}
			
			$result = $this->db->query($query);
			$nbrows = $result->num_rows();
			$limit = $query." LIMIT ".$start.",".$end;		
			$result = $this->db->query($limit);  
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}
		
		//function for update record
		function master_lesson_plan_update($lesplan_id, $lesplan_code ,$lesplan_teacher ,$lesplan_class ,$lesplan_theme, $lesplan_subtheme, $lesplan_note, $lesplan_month ,$lesplan_year , $lesplan_capacity,
			 $array_dplan_id, $array_dplan_time_start, $array_dplan_time_end, $array_dplan_daily_schedule, 
			 $array_dplan_week1_1, $array_dplan_week1_2, $array_dplan_week2_1, $array_dplan_week2_2, $array_dplan_week3_1, $array_dplan_week3_2, $array_dplan_week4_1, $array_dplan_week4_2){
			$data = array(
				// "anam_id"=>$lesplan_id, 
				// "anam_tanggal"=>$anam_tanggal, 
				"lesplan_note"=>$lesplan_note, 
				"lesplan_subtheme"=>$lesplan_subtheme, 
				"lesplan_theme"=>$lesplan_theme, 
				"lesplan_month"=>$lesplan_month, 
				"lesplan_year"=>$lesplan_year
				// "lesplan_capacity"=>$lesplan_capacity
			);

			// Cara untuk mengakali combobox yang pny datastore sendiri
			$sql="SELECT karyawan_id FROM karyawan WHERE karyawan_id='".$lesplan_teacher."'";
				$result=$this->db->query($sql);
				if($result->num_rows())
					$data["lesplan_teacher"]=$lesplan_teacher;

			$sql="SELECT class_id FROM class WHERE class_id='".$lesplan_class."'";
				$result=$this->db->query($sql);
				if($result->num_rows())
					$data["lesplan_class"]=$lesplan_class;


			$this->db->where('lesplan_id', $lesplan_id);
			$this->db->update('master_lesson_plan', $data);
			
			$temp_dplan_upd = $this->detail_lesson_plan_insert($lesplan_id, $array_dplan_id, $array_dplan_time_start, $array_dplan_time_end, $array_dplan_daily_schedule, 
			 $array_dplan_week1_1, $array_dplan_week1_2, $array_dplan_week2_1, $array_dplan_week2_2, $array_dplan_week3_1, $array_dplan_week3_2, $array_dplan_week4_1, $array_dplan_week4_2
			 );


			return $lesplan_id;
		}
		
		//function for create new record
		function master_lesson_plan_create($lesplan_code ,$lesplan_teacher ,$lesplan_class ,$lesplan_theme , $lesplan_subtheme, $lesplan_note, $lesplan_month ,$lesplan_year , $lesplan_capacity,
			 $array_dplan_id, $array_dplan_time_start, $array_dplan_time_end, $array_dplan_daily_schedule, 
			 $array_dplan_week1_1, $array_dplan_week1_2, $array_dplan_week2_1, $array_dplan_week2_2, $array_dplan_week3_1, $array_dplan_week3_2, $array_dplan_week4_1, $array_dplan_week4_2){
			
			$date_now = date('Y-m-d');
			$datetime_now = date('Y-m-d H:i:s');

			$tanggal_pattern=strtotime($date_now);
			$pattern="LP/".date("ym",$tanggal_pattern)."-";
			$lesplan_code=$this->m_public_function->get_kode_1('master_lesson_plan','lesplan_code',$pattern,12);
		

			$data = array(
				"lesplan_code"=>$lesplan_code, 
				"lesplan_teacher"=>$lesplan_teacher, 
				"lesplan_class"=>$lesplan_class, 
				"lesplan_theme"=>$lesplan_theme, 
				"lesplan_subtheme"=>$lesplan_subtheme, 
				"lesplan_note"=>$lesplan_note, 
				"lesplan_month"=>$lesplan_month, 
				"lesplan_year"=>$lesplan_year, 
				// "lesplan_capacity"=>$lesplan_capacity,
				"lesplan_date_create"=>$datetime_now
			);
			$this->db->insert('master_lesson_plan', $data); 

			$temp_lesplan_id = $this->db->insert_id();
			$temp_dplan_ins = $this->detail_lesson_plan_insert($temp_lesplan_id, $array_dplan_id, $array_dplan_time_start, $array_dplan_time_end, $array_dplan_daily_schedule, 
			 $array_dplan_week1_1, $array_dplan_week1_2, $array_dplan_week2_1, $array_dplan_week2_2, $array_dplan_week3_1, $array_dplan_week3_2, $array_dplan_week4_1, $array_dplan_week4_2
			 );

			if($this->db->affected_rows())
				return $this->db->insert_id();
			else
				return '0';
		}
		
		//fcuntion for delete record
		function anamnesa_delete($pkid){
			// You could do some checkups here and return '0' or other error consts.
			// Make a single query to delete all of the anamnesas at the same time :
			if(sizeof($pkid)<1){
				return '0';
			} else if (sizeof($pkid) == 1){
				$query = "DELETE FROM anamnesa WHERE anam_id = ".$pkid[0];
				$this->db->query($query);
			} else {
				$query = "DELETE FROM anamnesa WHERE ";
				for($i = 0; $i < sizeof($pkid); $i++){
					$query = $query . "anam_id= ".$pkid[$i];
					if($i<sizeof($pkid)-1){
						$query = $query . " OR ";
					}     
				}
				$this->db->query($query);
			}
			if($this->db->affected_rows()>0)
				return '1';
			else
				return '0';
		}
		
		//function for advanced search record
		function anamnesa_search($anam_id ,$anam_cust ,$anam_tanggal ,$anam_petugas ,$anam_pengobatan ,$anam_perawatan ,$anam_terapi ,$anam_alergi ,
								 $anam_obatalergi ,$anam_efekobatalergi ,$anam_hamil ,$anam_kb ,$anam_harapan ,$start,$end){
			//full query
			$query = "SELECT * FROM anamnesa,customer,karyawan
						WHERE anam_cust=cust_id AND anam_petugas=karyawan_id";
			
			
			if($anam_cust!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_cust LIKE '%".$anam_cust."%'";
			};
			if($anam_tanggal!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_tanggal LIKE '%".$anam_tanggal."%'";
			};
			if($anam_petugas!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_petugas LIKE '%".$anam_petugas."%'";
			};
			if($anam_pengobatan!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_pengobatan LIKE '%".$anam_pengobatan."%'";
			};
			if($anam_perawatan!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_perawatan LIKE '%".$anam_perawatan."%'";
			};
			if($anam_terapi!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_terapi LIKE '%".$anam_terapi."%'";
			};
			if($anam_alergi!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_alergi LIKE '%".$anam_alergi."%'";
			};
			if($anam_obatalergi!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_obatalergi LIKE '%".$anam_obatalergi."%'";
			};
			if($anam_efekobatalergi!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_efekobatalergi LIKE '%".$anam_efekobatalergi."%'";
			};
			if($anam_hamil!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_hamil LIKE '%".$anam_hamil."%'";
			};
			if($anam_kb!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_kb LIKE '%".$anam_kb."%'";
			};
			if($anam_harapan!=''){
				$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
				$query.= " anam_harapan LIKE '%".$anam_harapan."%'";
			};
			$result = $this->db->query($query);
			$nbrows = $result->num_rows();
			
			$limit = $query." LIMIT ".$start.",".$end;		
			$result = $this->db->query($limit);    
			
			if($nbrows>0){
				foreach($result->result() as $row){
					$arr[] = $row;
				}
				$jsonresult = json_encode($arr);
				return '({"total":"'.$nbrows.'","results":'.$jsonresult.'})';
			} else {
				return '({"total":"0", "results":""})';
			}
		}
		
		//function for print record
		function anamnesa_print($anam_id ,$anam_cust ,$anam_tanggal ,$anam_petugas ,$anam_pengobatan ,$anam_perawatan ,$anam_terapi ,$anam_alergi ,
								$anam_obatalergi ,$anam_efekobatalergi ,$anam_hamil ,$anam_kb ,$anam_harapan ,$option,$filter){
			//full query
			$query = "SELECT * FROM anamnesa,customer,karyawan
						WHERE anam_cust=cust_id AND anam_petugas=karyawan_id";
						
			if($option=='LIST'){
				$query .=eregi("WHERE",$query)? " AND ":" WHERE ";
				$query .= " (cust_nama LIKE '%".addslashes($filter)."%' OR 
							 karyawan_nama LIKE '%".addslashes($filter)."%' OR 
							 anam_alergi LIKE '%".addslashes($filter)."%' OR 
							 anam_obatalergi LIKE '%".addslashes($filter)."%'  )";
			} else if($option=='SEARCH'){
				
				if($anam_cust!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_cust LIKE '%".$anam_cust."%'";
				};
				if($anam_tanggal!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_tanggal LIKE '%".$anam_tanggal."%'";
				};
				if($anam_petugas!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_petugas LIKE '%".$anam_petugas."%'";
				};
				if($anam_pengobatan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_pengobatan LIKE '%".$anam_pengobatan."%'";
				};
				if($anam_perawatan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_perawatan LIKE '%".$anam_perawatan."%'";
				};
				if($anam_terapi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_terapi LIKE '%".$anam_terapi."%'";
				};
				if($anam_alergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_alergi LIKE '%".$anam_alergi."%'";
				};
				if($anam_obatalergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_obatalergi LIKE '%".$anam_obatalergi."%'";
				};
				if($anam_efekobatalergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_efekobatalergi LIKE '%".$anam_efekobatalergi."%'";
				};
				if($anam_hamil!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_hamil LIKE '%".$anam_hamil."%'";
				};
				if($anam_kb!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_kb LIKE '%".$anam_kb."%'";
				};
				if($anam_harapan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_harapan LIKE '%".$anam_harapan."%'";
				};
				
			}
			$result = $this->db->query($query);
			return $result;
		}
		
		//function  for export to excel
		function anamnesa_export_excel($anam_id ,$anam_cust ,$anam_tanggal ,$anam_petugas ,$anam_pengobatan ,$anam_perawatan ,$anam_terapi ,
									   $anam_alergi ,$anam_obatalergi ,$anam_efekobatalergi ,$anam_hamil ,$anam_kb ,$anam_harapan ,$option,$filter){
			//full query
			$query = "SELECT cust_no as 'No Cust', cust_nama 'Customer', anam_tanggal as Tanggal, karyawan_nama as Petugas,
						anam_pengobatan as Pengobatan, anam_perawatan as Perawatan, anam_terapi as Terapi, anam_alergi as Alergi,
						anam_obatalergi as 'Alergi terhadap Obat', anam_efekobatalergi as 'Efek Alergi', anam_hamil as Hamil, 
						anam_kb 'Alat KB yang digunakan', anam_harapan as Harapan FROM anamnesa,customer,karyawan
						WHERE anam_cust=cust_id AND anam_petugas=karyawan_id";
						
			if($option=='LIST'){
				$query .=eregi("WHERE",$query)? " AND ":" WHERE ";
				$query .= " (cust_nama LIKE '%".addslashes($filter)."%' OR 
							 karyawan_nama LIKE '%".addslashes($filter)."%' OR 
							 anam_alergi LIKE '%".addslashes($filter)."%' OR 
							 anam_obatalergi LIKE '%".addslashes($filter)."%'  )";
			} else if($option=='SEARCH'){
				
				if($anam_cust!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_cust LIKE '%".$anam_cust."%'";
				};
				if($anam_tanggal!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_tanggal LIKE '%".$anam_tanggal."%'";
				};
				if($anam_petugas!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_petugas LIKE '%".$anam_petugas."%'";
				};
				if($anam_pengobatan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_pengobatan LIKE '%".$anam_pengobatan."%'";
				};
				if($anam_perawatan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_perawatan LIKE '%".$anam_perawatan."%'";
				};
				if($anam_terapi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_terapi LIKE '%".$anam_terapi."%'";
				};
				if($anam_alergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_alergi LIKE '%".$anam_alergi."%'";
				};
				if($anam_obatalergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_obatalergi LIKE '%".$anam_obatalergi."%'";
				};
				if($anam_efekobatalergi!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_efekobatalergi LIKE '%".$anam_efekobatalergi."%'";
				};
				if($anam_hamil!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_hamil LIKE '%".$anam_hamil."%'";
				};
				if($anam_kb!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_kb LIKE '%".$anam_kb."%'";
				};
				if($anam_harapan!=''){
					$query.=eregi("WHERE",$query)?" AND ":" WHERE ";
					$query.= " anam_harapan LIKE '%".$anam_harapan."%'";
				};
				
			}
			$result = $this->db->query($query);
			return $result;
		}
		
}
?>